package net.melon.agency.pojo;

import java.util.HashSet;

import net.esj.auth.pojo.CoreAuthFunc;
import net.esj.basic.annotation.IgnorePrint;
import net.esj.basic.pojo.AbstractPojo;
import net.esj.basic.utils.CollectionUtils;
import net.esj.basic.utils.StringUtils;

public class AgencyGroup extends AbstractPojo<String> implements java.io.Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 4169404440660252418L;
	
	public static String AGENCY_GROUP_DEFAULT = "agency.group.default";
	
	private String id;
 	 /**
 		* 系统组为null.
     */
	private Agency agency;
	
	private String name;
	
	private String descriptions;
	
	private String funcsStr;
	
	private String agencyUseId;
	
	private java.util.Set<CoreAuthFunc> functions = new HashSet<CoreAuthFunc>(0);
	/**
	 * 判断如果不是系统组为1，否则默认为0
	 */
	private int agencyG;

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public Agency getAgency() {
		return agency;
	}

	public void setAgency(Agency agency) {
		this.agency = agency;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getDescriptions() {
		return descriptions;
	}

	public void setDescriptions(String descriptions) {
		this.descriptions = descriptions;
	}

	@IgnorePrint
	public java.util.Set<CoreAuthFunc> getFunctions() {
		if(CollectionUtils.isEmpty(functions)
				&& StringUtils.hasText(funcsStr)){
			resolveFunctionsByStr();
		}
		return functions;
	}

	public void setFunctions(java.util.Set<CoreAuthFunc> functions) {
		this.functions = functions;
	}

	public String getFuncsStr() {
		if(!StringUtils.hasText(funcsStr)&& !CollectionUtils.isEmpty(functions)){
			String[] strs = new String[functions.size()];
			int i =0 ;
			for(CoreAuthFunc func : functions){
				strs[i] = func.getId();
				i++;
			}
			funcsStr = StringUtils.join(strs, ";");
		}
		return funcsStr;
	}

	public void setFuncsStr(String funcsStr) {
		this.funcsStr = funcsStr;
	} 

	public void resolveFunctionsByStr(){
		if(StringUtils.hasText(funcsStr)){
			functions = new HashSet<CoreAuthFunc>();
			for(String id: funcsStr.split(";")){
				CoreAuthFunc func = new CoreAuthFunc();
				func.setId(id);
				functions.add(func);
			}
		}
	}

	public String getAgencyUseId() {
		return agencyUseId;
	}

	public void setAgencyUseId(String agencyUseId) {
		this.agencyUseId = agencyUseId;
	}

	public int getAgencyG() {
		return agencyG;
	}

	public void setAgencyG(int agencyG) {
		this.agencyG = agencyG;
	}

}


